<div class="modal-body">
	<form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="id" id="station_infoId">
		<input type="hidden" name="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<input type="hidden" id="deleted">
		<div class="box-body">
			<div class="col-md-6">
				<div class="form-group">
					<label for="station_name" class="col-sm-4 control-label">测站名称</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="station_name" name="station_name" placeholder="测站名称">
					</div>
				</div>
				<div class="form-group">
					<label for="station_id" class="col-sm-4 control-label">测站编号</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="station_id" name="station_id" placeholder="测站编号">
					</div>
				</div>
				<div class="form-group">
					<label for="location" class="col-sm-4 control-label">经度</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="location_lng" name="location_lng" placeholder="站点位置经度">
					</div>
				</div>
				<div class="form-group">
					<label for="admin_name" class="col-sm-4 control-label">测站管理员</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="admin_name" name="admin_name" placeholder="测站管理员">
					</div>
				</div>
				<div class="form-group">
					<label for="area_code" class="col-sm-4 control-label">管辖区域</label>
					<div class="col-sm-7">
							<select id="area_code" class="form-control" name="areaCode" style="margin-top:6px;">
								<option value="">请选择区域</option>
							</select>
					</div>
				</div>
				<div class="form-group">
					<label for="monitor_item" class="col-sm-4 control-label">监控指标名</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="monitor_item" name="monitor_item" placeholder="站点监控指标">
					</div>
				</div>
			</div>
			
			<div class="col-md-6">
				<div class="form-group">
					<label for="station_type" class="col-sm-4 control-label">站点类型</label>
					<div class="col-sm-7">
							<select id="station_type" class="form-control" name="station_type">
								<option value="" label="请选择站点类型"/>
							</select>
					</div>
				</div>
				<div class="form-group">
					<label for="location" class="col-sm-4 control-label">监测位置</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="location" name="location" placeholder="站点位置描述">
					</div>
				</div>
				<div class="form-group">
					<label for="location" class="col-sm-4 control-label">纬度</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="location_lat" name="location_lat" placeholder="站点位置纬度">
					</div>
				</div>
				<div class="form-group">
					<label for="admin_tel" class="col-sm-4 control-label">管理员电话</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="admin_tel" name="admin_tel" placeholder="管理员电话">
					</div>
				</div>
				<div class="form-group">
					<label for="zht_id" class="col-sm-4 control-label">灾害体</label>
					<div class="col-sm-7">
							<select id="zht_id" class="form-control" name="zht_id" style="margin-top:6px;">
								<option value="">请选择灾害体</option>
							</select>
					</div>
				</div>
				<div class="form-group">
					<label for="sort" class="col-sm-4 control-label">排序号</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" id="sort" name="sort" placeholder="站点排序号">
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<label for="sort" class="col-sm-2 control-label">描述</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="description" name="description" placeholder="站点描述">
					</div>
				</div>
			</div>
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button type="button" class="btn btn-primary" data-btn-type="save" onclick="save_station_info()">提交</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		view_station_info();
	});
	
	function view_station_info( fn ){
		//从datatable上获取已经选择的条目
		if( Dtable_station.rows('.selected').data().length > 0 ){
			var id = Dtable_station.rows('.selected').data()[0].id;
			$("#station_infoId").val( id );
			
			if( id == "null" ||id == null || id == undefined || id == "0" ){
				return false;
			}
			//说明是查询
			$("#id").val(id);
			$("[name='btn_sys_config_delete']").attr("disabled", false);
			var url = "../../tbl_station_info/" + id;
			$.getJSON(url, null, function(json){
				//向页面上加载信息
				if( json && json.data ){
					var station_info = json.data;
					$("#station_infoId").val(station_info.id);
					$("#station_name").val(station_info.station_name );
			 		$("#station_id").val(station_info.station_id);
			 		$("#location_lng").val(station_info.location_lng);
			 		$("#admin_name").val(station_info.admin_name);
			 		$("#area_code").val(station_info.area_code);
			 		$("#description").val(station_info.description);
			 		$("#monitor_item").val(station_info.monitor_item );
			 		$("#station_type").val(station_info.station_type );
			 		$("#location").val(station_info.location );
			 		$("#location_lat").val(station_info.location_lat );
			 		$("#admin_tel").val(station_info.admin_tel );
			 		$("#sort").val(station_info.sort );
			 		$("#deleted").val(station_info.deleted );
			 		$("#zht_id").val(station_info.zht_id );
			 		$("#description").val(station_info.description);
			 		
			 		initArea( "area_code", global.system_city_code, station_info.area_code );
					initZht( "zht_id", station_info.area_code, station_info.zht_id );
					initStationType( "station_type", station_info.station_type );
				}			
			});
		}
	}
	
	function initArea( sel_id, parent_code, sel_value ){
		var url = "../../tbl_area/list";
		var paramMap = {};
		paramMap.parent_code = parent_code;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
					  if( this.area_code == sel_value ){
						  $( "#" + sel_id ).append("<option value='"+ this.area_code +"' selected>"+ this.area_name +"</option>");
					  }else{
						  $( "#" + sel_id ).append("<option value='"+ this.area_code +"'>"+ this.area_name +"</option>");
					  }
				  });
			  }
		});
	}
	
	function initZht( sel_id, area_code, sel_value ){
		var url = "../../tbl_zht/list";
		var paramMap = {};
		if( area_code && area_code != "" ){
			paramMap.area_code = area_code;
		}
		paramMap.deleted = 0;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
					  if( this.id == sel_value ){
						  $( "#" + sel_id ).append("<option value='"+ this.id +"' selected>"+ this.name +"</option>");
					  }else{
						  $( "#" + sel_id ).append("<option value='"+ this.id +"'>"+ this.name +"</option>");
					  }
				  });
			  }
		});
	}
	
	function initStationType( sel_id, sel_value ){
		var url = "../../tbl_station_type/list";
		var paramMap = {};
		paramMap.deleted = 0;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
					  if( this.id == sel_value ){
						  $( "#" + sel_id ).append("<option value='"+ this.id +"' selected>"+ this.type_name +"</option>");
					  }else{
						  $( "#" + sel_id ).append("<option value='"+ this.id +"'>"+ this.type_name +"</option>");
					  }
				  });
			  }
		});
	}
	
	function save_station_info( fn ){
		var station_info = {};
		station_info.id = $("#station_infoId").val();
		station_info.station_name = $("#station_name").val();
		station_info.station_id = $("#station_id").val();
		station_info.location_lng = $("#location_lng").val();
		station_info.admin_name = $("#admin_name").val();
		station_info.area_code = $("#area_code").val();
		station_info.monitor_item = $("#monitor_item").val();
		station_info.station_type = $("#station_type").val();
		station_info.location = $("#location").val();
		station_info.location_lat = $("#location_lat").val();
		station_info.admin_tel = $("#admin_tel").val();
		station_info.zht_id = $("#zht_id").val();
		station_info.sort = $("#sort").val();
		station_info.deleted = $("#deleted").val();
		station_info.description = $("#description").val();
		var json_data = JSON.stringify( station_info );
		var url = "../../tbl_station_info/save";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert( json.message );
				 $("#station_info_main").load("station/station_info_list.html");
				 dialog_close();
			  }
		});
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>